package com.xiaohao.healthrecords.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiaohao.healthrecords.entity.Payment;
import com.xiaohao.healthrecords.mapper.PaymentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class PaymentService {
    @Autowired
    private PaymentMapper paymentMapper;

    public Payment query(Payment payment) {
        LambdaQueryWrapper<Payment> queryWrapper = new LambdaQueryWrapper<>(payment);
        return paymentMapper.selectOne(queryWrapper);
    }

    public List<Payment> queryList(Payment payment) {
        LambdaQueryWrapper<Payment> queryWrapper = new LambdaQueryWrapper<>(payment);
        return paymentMapper.selectList(queryWrapper);
    }

    public int update(Payment payment) {
        if (Objects.isNull(payment)){
            return 0;
        }
        if (Objects.nonNull(payment.getId())){
            return paymentMapper.updateById(payment);
        }else {
            return paymentMapper.insert(payment);
        }
    }

    public int delete(Integer id) {
        return paymentMapper.deleteById(id);
    }
}
